<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<% String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>新增/修改返利账号</title>
    <jsp:include page="../import.jsp" flush="true"/>
</head>
<script type="text/javascript">
var id = '${id}'
var disabled = '${disabled}'
var flag = false ;
$(function(){
	if(id){
		initData();
	}
	$("#formSet1").ligerForm({
        validate : true
    });
    $("#formSet1").ligerForm();

	if(disabled == 1){
		disableFiled();
	}
    bizTypCdChange();
})
function initData(){
	var _url = '<%=path%>/rebacc/salerebaccinfo/getById.do';
	$.ajax({
		type: 'get',
		dataType:'json',
		data:{id:id},
		url: _url,
		success:function(msg){
			 if(msg.success == 1){
				 setData(msg.data);//设置数据
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	});
}
function setData(data){
	setRgnProvCdUpdataValue(data.rgnPrCd);
	setRgnCityCdUpdataValue(data.rgnCyCd);
	$("#rcptUnt").val(data.rcptUnt);
	$("#accNo").val(data.accNo);
	$("#bkNm").val(data.bkNm);
	$("#bkNo").val(data.bkNo);
	$("#bkRem").val(data.bkRem);
	$("#contTel").val(data.contTel);
	//$("#purpCd").ligerGetComboBoxManager().selectValue(data.purpCd);
	$("#bizTypCd").val(data.bizTypCd);
	$("#purpCd").val(data.purpCd);

	var form = liger.get("formSet1");
	form.setData({
		bizTypCd:data.bizTypCd,
		purpCd:data.purpCd
	});

}

function disableFiled(){
	if (liger.get("rcptUnt")) {
        liger.get("rcptUnt").setDisabled(true);
    }
	if (liger.get("accNo")) {
        liger.get("accNo").setDisabled(true);
    }
	if (liger.get("bkNm")) {
        liger.get("bkNm").setDisabled(true);
    }
	if (liger.get("bkNo")) {
        liger.get("bkNo").setDisabled(true);
    }
	if (liger.get("bkRem")) {
        liger.get("bkRem").setDisabled(true);
    }
	//禁用省市
    disabledRgnProvCd();
    disabledRgnCityCd();
	if (liger.get("contTel")) {
        liger.get("contTel").setDisabled(true);
    }
	if (liger.get("bizTypCd")) {
        liger.get("bizTypCd").setDisabled(true);
    }
	$("#fileDIV").remove();
	$("#fileUploadDIV").remove();
	$("#noticeDIV").remove();
    $(".isPrivate").remove();
}

function bizTypCdChange(){
    $("#bizTypCd").change(function(event) {
        bizTypCd = $("#bizTypCd").val();
        if(bizTypCd==0){
            //账号类型对公
            $("#noticeDIV").show();
            $(".isPrivate").css('display','none');
            $("#bkResTel").rules('remove','required')
            $("#certNo").rules('remove','required')
        }else{
            //账号类型对私
            $("#noticeDIV").hide();
            $(".isPrivate").css('display','block');
            $("#bkResTel").rules("add",{required:true})
            $("#certNo").rules("add",{required:true})
        }
    });
}
	//定义父级调用事件
	frameElement.dialog.onOk = function () {
		flag = true ;
	     save();
	}

	frameElement.dialog.onCancel = function () {
	     frameElement.dialog.close();
	}
function save(){
	var form = liger.get("formSet1");
    if (!form.valid()) {
    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
        return false; //验证不通过，不执行以下代码
    }
    var data = form.getData();
    var _id = $("#sId").val();
    var docArray = JSON.stringify(getUploadResultParams());
    //赋值附件
    data["docArray"] = docArray;
    console.log(_id)
    data["rgnPrCd"] = getRgnProvCd();//获取省代码
    data["rgnCyCd"] = getRgnCityCd();//获取市代码
    var url = '';
    if(_id){
    	url = '<%=path%>/rebacc/salerebaccinfo/modify.do';
    	data["id"]= _id;
        data["disable"]= '1';
    }else{
    	if(data.bizTypCd == '0' && docArray.length <= 2 ){
    		$.ligerDialog.SQalert({content: "请上传附件信息！" , SQ_type: "warning" });
            return false; //验证不通过，不执行以下代码
    	}
    	url = '<%=path%>/rebacc/salerebaccinfo/add.do';
    }
    var wait_dialog;
    $.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: url,
		beforeSend: function(){
	          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
	     },
		success:function(msg){
			 wait_dialog.close();
			 if(msg.success == 1){
				 $("#sId").val(msg.data);
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
				 if(flag){
		             parent.callback();
		             frameElement.dialog.close();
			 	}
			 }else{
				 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
			 }
		}
	});
}
</script>
<body class="iframeBody">
<div class="Wrapper">
<div id="pageInTab" class="pageInTab">
	<div tabid="tabA" title="基本信息" lselected="true">
             <form id="formSet1">
              <div class="fieldset1 tabel_col clearFix">

              	<div class="caption">
                         <span class="title">基本信息</span>
                     </div>
				  <div class="fieldBox col_50">
					  <div class="label">账号类型</div>
					  <div class="field">
						  <select name="bizTypCd" id="bizTypCd" data-value=" " validate ="{required:true,select:true}">
							  <option value=" " seleted>请选择</option>
							  <c:forEach items="${bizTypCdList }" var="kv">
								  <option value="${kv.key }">${kv.value }</option>
							  </c:forEach>
						  </select>
						  <span class="requiredSymbol">*</span>
					  </div>
				  </div>
                     <div class="fieldBox col_50">
                         <div class="label">收款方</div>
                         <div class="field">
                             <input type="text" id="rcptUnt" name="rcptUnt" class="ui-textbox" validate ="{required:true}"/>
                             <span class="requiredSymbol">*</span>
                         </div>
                   </div>
                     <div class="fieldBox col_50">
                         <div class="label">收款账号</div>
                         <div class="field">
                             <input name="accNo" id="accNo"  type="text"
                                     class="ui-textbox" validate="{required:true}">
                             <span class="requiredSymbol">*</span>
                         </div>
                   </div>
                     <div class="fieldBox col_50">
                         <div class="label">开户行</div>
                         <div class="field">
                             <input name="bkNm" id="bkNm" type="text"
                                     class="ui-textbox" validate="{required:true}">
                             <span class="requiredSymbol">*</span>
                         </div>
                   </div>
                     <div class="fieldBox col_50">
                         <div class="label">开户行行号</div>
                         <div class="field">
                             <input name="bkNo" id="bkNo"  type="text"
                                     class="ui-textbox" validate="{required:true}">
                             <span class="requiredSymbol">*</span>
                         </div>
                   </div>
				  <div class="fieldBox col_50 isPrivate">
					  <div class="label">银行预留手机号</div>
					  <div class="field">
						  <input type="text" id="bkResTel" name="bkResTel" class="ui-textbox" validate ="{number:true}"/>
						  <span class="requiredSymbol">*</span>
					  </div>
				  </div>
				  <div class="fieldBox col_50 isPrivate">
					  <div class="label">收款方身份证号</div>
					  <div class="field">
						  <input type="text" id="certNo" name="certNo" class="ui-textbox"/>
						  <span class="requiredSymbol">*</span>
					  </div>
				  </div>
				  <div class="fieldBox col_50">
					  <div class="label">联系方式</div>
					  <div class="field">
						  <input name="contTel" id="contTel"  type="text"
								 class="ui-textbox" >
					  </div>
				  </div>
				  <div class="fieldBox col_66_auto">
					  <div class="label">区域</div>
					  <div class="field">
						  <jsp:include page="../system/sysRegion/region.jsp" flush="true" >
							  <jsp:param name="regionShowLvl" value="2"/>
						  </jsp:include>
						  <span class="requiredSymbol">*</span>
					  </div>
				  </div>
				<div class="fieldBox col_50">
	                <div class="label">账号用途</div>
	                <div class="field">
	                    <select name="purpCd" id="purpCd" data-value=" " validate ="{required:true,select:true}">
	                    	<option value=" " seleted>请选择</option>
	                       <c:forEach items="${purpCdList }" var="kv">
	                     		<option value="${kv.key }">${kv.value }</option>
	                       </c:forEach>
	                    </select>
	                    <span class="requiredSymbol">*</span>
	                </div>
            	</div>

                   <div class="fieldBox col_100">
					<div class="label">备注</div>
					<div class="field">
						<input type="text" id="bkRem" name="bkRem" class="ui-textbox" />
					</div>
					</div>
					<div id="fileDIV" class="fieldBox col_100" id="fileModify">
					<div class="label">资料</div>
					<div class="field">
	                	<jsp:include page="../system/sysUlFilesRec/sysUlFileRecList.jsp" flush="true" >
	                   		<jsp:param name="pkId" value="${id }"/>
	                   		<jsp:param name="tabNm" value="SALE_REB_ACC_INFO"/>
	                 	</jsp:include>
	            	</div>
					</div>
					<div id="fileUploadDIV" class="fieldBox col_100">
						<div class="label">资料上传</div>
						<div class="field">
		                   	<jsp:include page="../system/sysUlFilesRec/sysSysUlFilesRecUpload2.jsp" flush="true" >
		                   		<jsp:param name="filePath" value="/rebacc"/>
		                   	</jsp:include>
						</div>
					</div>
					<div id="noticeDIV" class="fieldBox col_100">
						<div class="label">注:</div>
						<div class="field">
							<span name="" id="" style="color: red;">对公账号需上传企业营业执照.</span>
						</div>
					</div>
					<input name="sId" id="sId" type="hidden" value="${id }">
            </div>
            <c:if test="${isButton == 1}">
             <div class="btnsBox">
                <span id="saveBtn1" onclick="save();" class="sq-button sq-button-round">保存</span>
		     </div>
		     </c:if>
         </form>
     </div>
</div>
</div>

</body>
</html>